<template>
	<view class="cocmResult-wrap" v-if="inquiry">
		<view class="cocmResult-container">
			<view class="cocmResult-title">诊断报告分析({{ score }})</view>

			<view class="cocmResult-tendency">
				<view class="cocmResult-score">您的体质结果：</view>
				<view class="cocmResult-que">{{ result }}{{ cocmDetail.name }}</view>
			</view>

			<view v-if="configIndex != 3">
				<view class="cocmResult-info">表象特征</view>
				<rich-text :nodes="cocmDetail.ideaTrait"></rich-text>

				<view class="cocmResult-info">体质调理</view>
				<rich-text :nodes="cocmDetail.conditioning"></rich-text>

				<view class="cocmResult-info">中医调养建议</view>

				<rich-text :nodes="cocmDetail.recuperat"></rich-text>

	
				<view class="quest-remark">以上诊断仅供参考，请在医生指导下就医</view>
			</view>

			<view @click="gotoRouter('/pages-client/cocm/cocmSelect')" class="quest-foolt">重新测试</view>
			<view @click="backHome" class="quest-foolt">回到首页</view>
		</view>
	</view>
</template>

<script>
export default {
	data: () => ({
		id: null,
		score: 0,
		result: '',
		cocmDetail: {},
		cocmConfig: [
			{
				name: '是',
				value: 60
			},
			{
				name: '基本是',
				value: 40
			},
			{
				name: '倾向是',
				value: 30
			},
			{
				name: '不是',
				value: 0
			}
		],
		configIndex: 0
	}),
	onLoad(option) {
		this.id = option.id;
		this.score = parseInt(option.score);
		this.queryCocmDetail();
	},
	mounted() {},
	methods: {
		//查询详情
		queryCocmDetail() {
			this.$api
				.queryCocmDetail({
					params: {
						id: this.id
					}
				})
				.then(res => {
					if (res.code == 200 && res.result) {
						this.cocmDetail = res.result;

						try {
							this.cocmConfig.forEach((item, index) => {
								//计算结果的倾向
								if (this.score >= item.value) {
									this.configIndex = index;
									throw new Error(index);
								}
							});
						} catch (e) {
							console.log('得到结果为：' + this.cocmConfig[e.message].name);
						}

						this.result = this.cocmConfig[this.configIndex].name;
						this.uploadCocmResult();
					}
				});
		},

		//上传体质测试结果
		uploadCocmResult() {
			this.$api
				.uploadCocmResult({
					params: {
						id: this.id,
						result: this.result,
						score: this.score
					}
				})
				.then(res => {
					if (res.code == 200 && res.result) {
						console.log('上传成功');
					}
				});
		},

		backHome() {
			uni.reLaunch({
				url: '/pages/index/index'
			});
		}
	}
};
</script>

<style lang="less">
page {
	padding: 0;
}
.cocmResult-wrap {
	background-color: #8c5e5b;
	width: 750rpx;
	min-height: 100vh;
	padding: 30rpx;
	box-sizing: border-box;

	.cocmResult-container {
		background-color: #fff;
		min-height: 94vh;
		padding: 24rpx;
		box-sizing: border-box;
		position: relative;
		border-radius: 30rpx;
		.cocmResult-title {
			background-color: #8c5e5b;
			width: 280rpx;
			height: 80rpx;
			border-radius: 10rpx;
			font-size: 32rpx;
			color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
			margin: 0 auto 48rpx;
		}

		.cocmResult-tendency {
			margin-bottom: 24px;
			display: flex;

			.cocmResult-score {
				font-size: 18px;
			}

			.cocmResult-que {
				font-size: 18px;
				font-weight: bold;
				color: #8c5e5b;
			}
		}

		.cocmResult-info {
			font-size: 32rpx;
			font-weight: bold;
			text-align: center;
			margin: 20rpx 0;
		}



		.quest-remark {
			margin-top: 62rpx;
			font-size: 28rpx;
			color: rgba(153, 153, 153, 1);
			text-align: right;
		}

		.quest-foolt {
			margin-top: 20px;
			width: 100%;
			height: 50px;
			background-color: #fff;
			box-sizing: border-box;
			color: #2d8cf0;
			font-size: 16px;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			text-align: center;
			line-height: 50px;
		}
	}
}
</style>
